/*
 * Copyright (c) 2022.版权所有高金磊
 */

package 领扣算法.A简单题.人口最多的年份;

public class Main {
    public int maximumPopulation(int[][] logs) {
        int nums[]=new int[2050-1950+2];
        //离散化数据
        for (int[] log : logs) {
            nums[log[0]-1950+1]+=1;
            nums[log[1]-1950+1]-=1;
        }
        //前缀和
        for (int i = 1; i < nums.length; i++) {
            nums[i]+=nums[i-1];
        }
        int year=0;
        for (int i = 1; i < nums.length; i++) {
            if(nums[i]>nums[0])
            {
                nums[0]=nums[i];
                year=i;
            }
        }
        return year+1950-1;
    }
}
